import { Sprite } from "@/sprites/Sprite.js";

export class SpritePool{
    /**
     * @type {Sprite[]}
     */
    static pool=[];

    static newSprite(source){
        let sprite=null;
        if(this.pool.length){
            sprite=this.pool.pop();
            sprite.source=source;
        }else{
            sprite=new Sprite(source);
        }
        return sprite;
    }

    static releaseSprite(sprite){
        if(sprite){
            this.pool.push(sprite);
        }
    }

    static close(){
        for(let sprite of this.pool){
            sprite.destroy();
        }
    }
}